package cn.copera.dyy.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.copera.dyy.common.service.BaseService;
import cn.copera.dyy.dao.LogDao;
import cn.copera.dyy.entity.Log;
/**
 * 日志service
 * @author Administrator
 *
 */
@Service
@Transactional(readOnly = true)
public class LogService extends BaseService {
	
	@Autowired
	private LogDao logDao;

	@Transactional(readOnly = false)
	public void save(Log log) {
		logDao.clear();
		logDao.save(log);
	}
	
    public Log find(String shopId, String ruleId, String nickName){
		
    	List<Log> list = logDao.find("from Log where shop.id = '"+shopId+"' and rule.id = '"+ruleId+"' and openid = '"+nickName+"' order by createDate desc");
    	
    	if (list != null && !list.isEmpty()) {
			return list.get(0);
		}
    	return null;
	}
    
    @Transactional(readOnly = false)
    public void deleteById(String id){
    	logDao.deleteRealById(id);
    }
}
